﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Resources;
using System.Threading;

namespace Caduceu.Estudos.Erros
{
    public class Messages
    {
        private static ResourceManager resourceManagerInstance = null;

        protected static ResourceManager GetResourceManager()
        {
            if (resourceManagerInstance == null)
                resourceManagerInstance = new ResourceManager("Caduceu.Estudos.Erros.ErrMessages", Assembly.GetExecutingAssembly());

            return resourceManagerInstance;
        }
        
        public static string GetMessage(string errorCode)
        {
            string erro = GetResourceManager().GetString(errorCode);
            
            if (string.IsNullOrEmpty(erro))
                throw new Exception("ERR_0000 - UNDOCUMENTED ERROR");

            return erro;
        }

        public static string GetMessage2(string errorCode)
        {
            return string.Format("{0} - {1}", errorCode, GetMessage(errorCode));
        }
    }
}
